#Name: tracegen.pl
#Description: Perl Script which generates trace file modelling CPU transactions 
#Author: ChinniKrishna Kothapalli
#!/usr/bin/perl
#Open a Trace file for writing
open (File,'>Trace.txt');
#Command List
@Commands=('MEMW','MEMR','IOW','IOR');
print File "RST\n";
#Loops for ARGV number of times
for($Count=1;$Count<=$ARGV[0];$Count++)
{
	$CommandIndex=int(rand(4));	    #Generate a random command index
	$Addr=int(rand(1048576));		#Generate a address.
	$Addr=(sprintf("%x",$Addr));	#Convert to hexadecimal
	$Data=int(rand(65536));			#Generate random 16-bit data.
	$Data=(sprintf("%x",$Data));  #Convert to hexadecimal
	#If the command is IO or Memory Write then make the waitstates zero
	$WaitStates=int(rand(4))+1;
	#Write the generated random values to file
	print File $Commands[$CommandIndex]," ",$Addr," ",$Data," ",$WaitStates," ","\n";
}
#Close the file
close(File);
